/*
 * Copyright (c) [2019] [Peking University]
 * [BDWare-DOIP] is licensed under the Mulan PSL v1.
 * You can use this software according to the terms and conditions of the Mulan PSL v1.
 * You may obtain a copy of Mulan PSL v1 at:
 *
 *   http://license.coscl.org.cn/MulanPSL
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v1 for more details.
 */
package bdware.netty.codec.doip;

import com.google.gson.Gson;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MessageEncoder extends MessageToByteEncoder<DOMessage> {
    @Override
    protected void encode(ChannelHandlerContext ctx, DOMessage msg, ByteBuf out) throws Exception {
        out.writeByte(msg.majorVersion);
        out.writeByte(msg.minVersion);
        out.writeByte(msg.flag);
        out.writeByte(0);
        out.writeInt(0);
        out.writeInt(msg.requestId);
        out.writeInt(msg.sequenceNumber);
        out.writeInt(msg.msgLength);
        encodeHeader(out, msg);
        encodeBody(out, msg);
        encodeCredential(out, msg);
    }

    private void encodeBody(ByteBuf out, DOMessage msg) {}

    private void encodeCredential(ByteBuf out, DOMessage msg) {}

    private void encodeHeader(ByteBuf out, DOMessage msg) {}
}
